<?php

date_default_timezone_set('PRC'); // 切换到中国的时间
require_once ("../config.php");
require_once ("../log.php");
require_once ("../api/api_tool.php");
/** 
 * @name Api接口demo（php版）
 * @desc 本接口列表，只是用于系统处理机器人行为
 * 一分钟执行一次，给符合条件的机器人发送
 */

$hm_time = substr(date('Y-m-d H:i:s',time()), 11, 5);
$host = "robot.centent.yykjgame.com";
$port = 80;

// $hm_time = "04:00";
// $host = "127.0.0.1";
// $port = 80;

// 发送微信心跳包
function sendHeartBeat($host, $port) {
	$url = "/timeTask/sendHeartBeat.php";
	sendFZSHttp($host, $port, $url, $data);
}

// 执行云发单任务
function botsendAction($host, $port) {
	$url = "/timeTask/botSendAction.php";
	sendFZSHttp($host, $port, $url, $data);
}

// 更新商品接口
function updateGoodList($host, $port) {
	simQuery("TRUNCATE TABLE item_ordinary");					// 清理商品表
	simQuery("UPDATE wechat_group SET send_item_id = ''");		// 清理微信群发送过的商品数据
	// 更新淘宝订单
	$url = "/api/api_taobao/good.php";
	sendFZSHttp($host, $port, $url, $data);

	// 更新京东订单
	$url = "/api/api_jd/good.php";
	sendFZSHttp($host, $port, $url, $data);

	// 更新拼多多订单
	$url = "/api/api_pdd/good.php";
	sendFZSHttp($host, $port, $url, $data);
}

// 执行清除图片任务
function clearBotData($host, $port) {
	$url = "/timeTask/clearBotData.php";
	sendFZSHttp($host, $port, $url, $data);
}

// 中午统计
function noon_statistics_data($host, $port, $state = 0) {
	$url = "/timeTask/noonStatisticsData.php";
	if ($state == 1) {
		$data['sign'] = '1';
	}
	sendFZSHttp($host, $port, $url, $data);
}

// 晚上统计
function night_statistics_data($host, $port, $state = 0) {
	$url = "/timeTask/nightStatisticsData.php";
	if ($state == 1) {
		$data['sign'] = '1';
	}
	sendFZSHttp($host, $port, $url, $data);
}

// 发送心跳
sendHeartBeat($host, $port);
if ($hm_time <= "20:00") {
	botsendAction($host, $port);
}

if ($hm_time == "04:00") {
	updateGoodList($host, $port);
	// clearBotData($host, $port);
}

// 中午统计
if ($hm_time >= "12:00" && $hm_time <= "13:00") {
	if ($hm_time == "12:00") {
		noon_statistics_data($host, $port, 1);
	} else {
		noon_statistics_data($host, $port);
	}
}

// 晚上统计
if ($hm_time >= "20:00" && $hm_time <= "21:00") {
	if ($hm_time == "20:00") {
		night_statistics_data($host, $port, 1);
	} else {
		night_statistics_data($host, $port);
	}
}

?>